package com.wst.system.controller;

import com.alibaba.fastjson2.JSONObject;
import com.wst.system.security.IsAdmin;
import com.wst.system.util.ResultUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wst.system.config.exception.GlobalExcetion;
import java.io.Serializable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.wst.system.server.service.SysOpenTokenService;
import com.wst.system.server.entity.SysOpenToken;
import com.wst.business.entity.vo.SysOpenTokenVo;
import org.springframework.validation.annotation.Validated;
import java.util.List;
import com.wst.system.config.PageData;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author X.I.O
 * @since 2025-02-10
 */

@RestController
@Api(tags = {"的服务类"})
@RequestMapping("/sys-open-token")
public class SysOpenTokenController  {

        @Autowired
        private SysOpenTokenService sysOpenTokenService;




        @IsAdmin
        @DeleteMapping("/delbyid")
        @ApiOperation(value = "的删除接口",notes = "的删除接口")
        public JSONObject delete(@RequestParam("id") Serializable id) throws GlobalExcetion{
            boolean flag = sysOpenTokenService.removeById(id);
            if(flag){
                return ResultUtil.successInfo("删除成功");
            }else {
                return ResultUtil.errorInfo("删除失败");
            }
        }

        @IsAdmin
        @PostMapping("/del/batch")
        @ApiOperation(value = "的批量删除接口",notes = "的批量删除接口")
        public JSONObject deleteBatch(@RequestBody List<Integer> ids) throws GlobalExcetion {
            boolean flag =  sysOpenTokenService.removeByIds(ids);
            if(flag){
                return ResultUtil.successInfo("删除成功");
            }else {
                return ResultUtil.errorInfo("删除失败");
            }
        }

        @GetMapping("/getall")
        @ApiOperation(value = "的获取全部接口",notes = "的获取全部接口")
        public JSONObject findAll() throws GlobalExcetion {
            List<SysOpenToken> list= sysOpenTokenService.list();
            return ResultUtil.successInfo(list);
        }

        @GetMapping("/getbyid")
        @ApiOperation(value = "的获取一个接口",notes = "的获取一个接口")
        public JSONObject findOne(@RequestParam("id") Serializable id) throws GlobalExcetion {
            SysOpenToken data= sysOpenTokenService.getById(id);
            return ResultUtil.successInfo(data);
        }

        @GetMapping("/page")
        @ApiOperation(value = "的分页接口",notes = "的分页接口")
        public JSONObject findPage(@RequestParam(value = "page",defaultValue = "1") Integer page,
                                   @RequestParam(value = "pageSize",defaultValue = "10")Integer pageSize) throws GlobalExcetion {
            IPage<SysOpenToken> data=sysOpenTokenService.page(page, pageSize);
            PageData pageData=new PageData(data.getTotal(),page,pageSize,data.getRecords());
            return ResultUtil.successInfo(pageData);
        }
}

